﻿<Window x:Class="WPF101_Data_XML.XMLListBox"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Data Binding XML" Height="300" Width="720" Loaded="Window_Loaded">
    <Window.Resources>
        <XmlDataProvider x:Key="InventoryData" XPath="Inventory">
            <x:XData>
                <Inventory xmlns="">
                    <Books>
                        <Book ISBN="0-7356-0562-9" Stock="in" Number="9">
                            <Title>XML in Action</Title>
                            <Summary>XML Web Technology</Summary>
                        </Book>
                        <Book ISBN="0-7356-1370-2" Stock="in" Number="8">
                            <Title>Programming Microsoft Windows With C#</Title>
                            <Summary>C# Programming using the .NET Framework</Summary>
                        </Book>
                        <Book ISBN="0-7356-1288-9" Stock="out" Number="7">
                            <Title>Inside C#</Title>
                            <Summary>C# Language Programming</Summary>
                        </Book>
                        <Book ISBN="0-7356-1377-X" Stock="in" Number="5">
                            <Title>Introducing Microsoft .NET</Title>
                            <Summary>Overview of .NET Technology</Summary>
                        </Book>
                        <Book ISBN="0-7356-1448-2" Stock="out" Number="4">
                            <Title>Microsoft C# Language Specifications</Title>
                            <Summary>The C# language definition</Summary>
                        </Book>
                    </Books>
                    <CDs>
                        <CD Stock="in" Number="3">
                            <Title>Classical Collection</Title>
                            <Summary>Classical Music</Summary>
                        </CD>
                        <CD Stock="out" Number="9">
                            <Title>Jazz Collection</Title>
                            <Summary>Jazz Music</Summary>
                        </CD>
                    </CDs>
                </Inventory>
            </x:XData>
        </XmlDataProvider>
    </Window.Resources>

    <DockPanel Background="Cornsilk">
        <!--Alternatively, you can do the following. -->
        <!--<ListBox Width="400" Height="300" Background="Honeydew"
            ItemsSource="{Binding Source={StaticResource InventoryData},
            XPath=*[@Stock\=\'out\'] | *[@Number>\=8 or @Number\=3]}">-->
        
        
        <TextBlock DockPanel.Dock="Top" FontSize="18" FontWeight="Bold" Margin="10" HorizontalAlignment="Center">XML Data Source Sample</TextBlock>
        <ListBox DockPanel.Dock="Left" Width="Auto" Height="Auto" Background="Honeydew">
            <ListBox.ItemsSource>
                <Binding Source="{StaticResource InventoryData}" XPath="Books/*"></Binding>
            </ListBox.ItemsSource>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Margin="3">
                        <TextBlock FontSize="12" Foreground="Red">
                            <TextBlock.Text>
                                <Binding XPath="Title"/>
                            </TextBlock.Text>
                        </TextBlock>
                        <TextBlock>
                            <TextBlock.Text>
                                <Binding XPath="Summary"></Binding>
                            </TextBlock.Text>                                                
                        </TextBlock>                     
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <ListBox DockPanel.Dock="Right">
            <ListBox.ItemsSource>
                <Binding Source="{StaticResource InventoryData}" XPath="CDs/*"></Binding>
            </ListBox.ItemsSource>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="150"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <TextBlock Margin="3,3,3,3" Grid.Column="0" Text="{Binding XPath=Title}"></TextBlock>
                            <TextBlock Margin="3,3,3,3" Grid.Column="1" Text="{Binding XPath=Summary}"></TextBlock>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </DockPanel>
</Window>
